package com.ts.api.module.api.entity.bo;

import com.gitee.apanlh.util.base.CollUtils;
import com.gitee.apanlh.util.base.IteratorUtils;
import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.ts.api.module.api.entity.vo.ReqApiParameterVO;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 *  过滤请求参数业务实体
 *
 *  @author Pan
 */
@Data
public class ApiFilterParamBO {

    /**
     *  过滤参数集合
     */
    private List<String> listFilterParam;

    public ApiFilterParamBO() {
        super();
        if (listFilterParam == null) {
            listFilterParam = CollUtils.newArrayList();
        }
    }

    /**
     *  过滤Api请求formMap(自定义参数)
     *
     *  @param  reqApiParameterVO
     *  @return Map
     */
    public Map<String, String> filterMap(ReqApiParameterVO reqApiParameterVO) {
        if (ValidParam.isEmpty(listFilterParam)) {
            return reqApiParameterVO.getFormMap();
        }

        Map<String, String> map = MapUtils.newHashMap(reqApiParameterVO.getFormMap());
        IteratorUtils.array(listFilterParam, t -> map.remove(t));
        return map;
    }

    /**
     *  创建
     *  @param str
     *  @return
     */
    public static ApiFilterParamBO create(String... str) {
        ApiFilterParamBO apiFilterParamBO = new ApiFilterParamBO();
        CollUtils.addAll(apiFilterParamBO.getListFilterParam(), str);
        return apiFilterParamBO;
    }
}
